<?php
/*
	Copyright © Eleanor CMS
	URL: http://eleanor-cms.ru, http://eleanor-cms.com
	E-mail: support@eleanor-cms.ru
	Developing: Alexander Sunvas*
	Interface: Rumin Sergey
	=====
	*Pseudonym
*/
function GetQuestionDates($y,$m,$conf)
{	$ds=Eleanor::$Cache->Get($conf['n'].'_calendar_'.$y.'_'.$m);
	if($ds===false)
	{		$ds=array();
		$R = Eleanor::$Db->Query('SELECT IF(`pinned` IS NULL,`date`,`pinned`) `date`, COUNT(`id`) `cnt` FROM `'.$conf['t'].'` WHERE IF(`pinned` IS NULL,`date`,`pinned`) LIKE \''.$y.'-'.str_pad($m,2,'0',STR_PAD_LEFT).'%\' AND `status`=1 GROUP BY DAY(IF(`pinned` IS NULL,`date`,`pinned`)) LIMIT 31');
		while($arr=Eleanor::$Db->FetchRow())
			$ds[str_replace('-','',substr($arr[0],0,10))]=$arr[1];
		Eleanor::$Cache->Put($conf['n'].'_calendar_'.$y.'_'.$m,$ds,3600);	}	return$ds;}

function QuestionCalendar($y,$m,$dates,$id,$conf,$url)
{global$Eleanor;	$tday=date('j');
	$tmon=$y==date('Y') && $m==date('n');
	$calendar=Dates::BuildCalendar($y,$m,false);
	$lang=Eleanor::$Language[$conf['n']];

	$c='<div class="blockcalendar" id="'.$conf['n'].'-calendar"><div class="month"><h4>'.Eleanor::$Language->Date($y.'-'.$m,'my').'</h4><span class="selyears"><a href="#" onclick="return '.$id.'.SubYear()" title="'.$lang['year-'].'"><img src="'.Eleanor::GetImage('engine/year_minus.png').'" alt="'.$lang['year-'].'" /></a><a href="#" onclick="return '.$id.'.AddYear()"><img src="'.Eleanor::GetImage('engine/year_plus.png').'" alt="'.$lang['year+'].'" /></a></span><div class="clr"></div></div><table><tr class="c_days"><td>'.$lang['mon'].'</td><td>'.$lang['tue'].'</td><td>'.$lang['wed'].'</td><td>'.$lang['thu'].'</td><td>'.$lang['fri'].'</td><td class="vday">'.$lang['sat'].'</td><td class="vday">'.$lang['sun'].'</td></tr>';
	$cnt=0;
	foreach($calendar as &$week)
	{
		$c.='<tr>';
		foreach($week as $k=>&$day)
		{
			$cl=$tmon && $day==$tday ? 'today' : false;
			if($k>4)
				$cl=$cl ? 'tovday' : 'vday';
			if($day)
			{
				$day=sprintf('%02d',$day);
				$m=sprintf('%02d',$m);
				if(isset($dates[$y.$m.$day]))
				{
					$cnt+=$dates[$y.$m.$day];
					$td='<a href="'.$Eleanor->Url->special.$Eleanor->Url->Construct(array('module'=>$url,'do'=>$Eleanor->Url->Filter($y.'-'.$m.'-'.$day)),false,'').'" title="'.sprintf($lang['_question'],$dates[$y.$m.$day]).'">'.$day.'</a>';
				}
				else
					$td=$day;
			}
			$c.='<td'.($cl ? ' class="'.$cl.'"' : '').'>'.($day ? $td : '&nbsp;').'</td>';
		}
		$c.='</tr>';
	}
	$pm=$nm=$m;
	$py=$ny=$y;
	if($nm==12)
	{		$ny++;
		$nm=1;	}
	else
		$nm++;
	if($pm==1)
	{
		$py--;
		$pm=12;
	}
	else
		$pm--;
	$n=Eleanor::$Language->Date(array('Y'=>$ny,'n'=>$nm),'my');
	$p=Eleanor::$Language->Date(array('Y'=>$py,'n'=>$pm),'my');
	$n=substr($n,0,strpos($n,' '));
	$p=substr($p,0,strpos($p,' '));
	return$c.'</table><div class="arrows"><a class="arrowleft" href="#" onclick="return '.$id.'.SubMonth()">'.$p.'</a><a class="arrowright" href="#" onclick="return '.$id.'.AddMonth();">'.$n.'</a><hr /></div><div style="text-align:center">'.($cnt>0 ? '<a href="'.$Eleanor->Url->Construct(array('module'=>$url,'do'=>$Eleanor->Url->Filter($y.'-'.$m)),false,'').'">'.sprintf($lang['total'],$cnt).'</a>' : $lang['no_per_question']).'</div></div>';
}
?>